package com.Ajava1801D.并发包.semphfore;

import java.util.concurrent.Semaphore;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2020/10/7  15:42
 * 描述:
 */
public class SemRun2222 implements Runnable {

    private Semaphore semaphore;

    private int sends;

    public SemRun2222(Semaphore semaphore, int sends) {
        this.semaphore = semaphore;
        this.sends = sends;
    }

    @Override
    public void run() {

        try {
            semaphore.acquire();
            Thread.sleep(sends*1000);
            System.out.println("==============="+Thread.currentThread().getName()+"====获得资源");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            semaphore.release();
        }

    }
}
